package com.kfc.platform.user.domain;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import com.sun.org.glassfish.gmbal.NameValue;
//@PersistenceContext(unitName="persistenceUnit") 
@Entity
@Table(name = "kfc_user")
@GenericGenerator(name = "user", strategy = "native")
public class User {
	private static final String USERNAME_STRATEGY = "^(?!_)(?!.*?_$)[a-zA-Z0-9_]$ ";//5-31位用户名，只能包含字母数字和下划线
	private static final String PASSWORD_STRATEGY = "^[a-zA-Z]d{5,15}$"  ;//6-16位字母开头密码，只能包含字符和数字
	private static final String CELLPHONE_STRATEGY ="^((13[0-9])|(15[0-9])|(18[0-9]))\\d{8}$";//手机号13,15,18开头
	private int id;//用户ID识别码
    private Integer version;//版本控制
	private String username;//用户名
	private String password;//密码
	private String email;//邮箱
	private String phonenum;//手机号
	private String date;//注册时间
	@Id
	@GeneratedValue(generator = "user")
	public int getId() {
		return id;
	}
	@Column(unique=true,nullable=false)
	@Size(min=6,max=32)
	@NotNull(message="用户名不能为空！")
	//@Pattern(regexp=USERNAME_STRATEGY,message="用户名只能有字母、数字和下划线")
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	@Column(nullable=false)
	@Size(min=6,max=16)
	@NotNull(message="密码不能为空！")
	//@Pattern(regexp=PASSWORD_STRATEGY,message="密码只能由字母和数字组成")
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	@Column
	@Email
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	@Pattern(regexp=CELLPHONE_STRATEGY,message="手机号码格式错误！")
	public String getPhonenum() {
		return phonenum;
	}
	public void setPhonenum(String phonenum) {
		this.phonenum = phonenum;
	}
	//@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public void setId(int id) {
		this.id = id;
	}
	@Version
	public Integer getVersion() {
		return version;
	}
	public void setVersion(Integer version) {
		this.version = version;
	}
}
